library(DT)
library(dplyr)
# Format Instantaneous Growth
instant_table <- bind_rows(
top_instant |> mutate(
`5-Year Population Growth` = round(pop_growth_5yr, 0),
`Population Growth Rate` = round(pop_growth_rate, 2),
`Instantaneous Growth Index` = round(housing_instant_index, 2),
Category = "Top 5"
),
bottom_instant |> mutate(
`5-Year Population Growth` = round(pop_growth_5yr, 0),
`Population Growth Rate` = round(pop_growth_rate, 2),
`Instantaneous Growth Index` = round(housing_instant_index, 2),
Category = "Bottom 5"
)
) |>
select(
Category,
CBSA,
`CBSA by Name` = NAME,
`5-Year Population Growth`,
`Population Growth Rate`,
`Instantaneous Growth Index`
)
# Format Rate Based Growth
rate_table <- bind_rows(
top_rate |> mutate(
`5-Year Population Growth` = round(pop_growth_5yr, 0),
`Population Growth Rate` = round(pop_growth_rate, 2),
`Rate Based Growth Index` = round(housing_rate_index, 2),
Category = "Top 5"
),
bottom_rate |> mutate(
`5-Year Population Growth` = round(pop_growth_5yr, 0),
`Population Growth Rate` = round(pop_growth_rate, 2),
`Rate Based Growth Index` = round(housing_rate_index, 2),
Category = "Bottom 5"
)
) |>
select(
Category,
CBSA,
`CBSA by Name` = NAME,
`5-Year Population Growth`,
`Population Growth Rate`,
`Rate Based Growth Index`
)
# Format Composite Index
composite_table <- bind_rows(
top_composite |> mutate(
`5-Year Population Growth` = round(pop_growth_5yr, 0),
`Population Growth Rate` = round(pop_growth_rate, 2),
`Composite Index` = round(composite_index, 2),
Category = "Top 5"
),
bottom_composite |> mutate(
`5-Year Population Growth` = round(pop_growth_5yr, 0),
`Population Growth Rate` = round(pop_growth_rate, 2),
`Composite Index` = round(composite_index, 2),
Category = "Bottom 5"
)
) |>
select(
Category,
CBSA,
`CBSA by Name` = NAME,
`5-Year Population Growth`,
`Population Growth Rate`,
`Composite Index`
)
# Create all 3 datatables
datatable(instant_table,
rownames = FALSE,
caption = "Top/Bottom 5 CBSAs by Instantaneous Growth Index (2014–2019)",
options = list(pageLength = 10, autoWidth = TRUE)
) |>
formatRound(columns = c("5-Year Population Growth",
"Population Growth Rate",
"Instantaneous Growth Index"), digits = 2) |>
formatCurrency(columns = "5-Year Population Growth", currency = "", interval = 3, mark = ",")